<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta charset="UTF-8"></meta>
    <title>登陆 - 有乐窝</title>
    <#include "include/common.html">
        </head>
<body>
<div class="header" id="header">登录</div>
<div class="main">
    <div class="register">
        <form class="u-form">
            <div class="form-item">
                <div class="item-tit">账号：</div>
                <div class="item-input"><input type="text" name="account" checkData="{rq:true,msg:'请输入正确的账号'}"
                                               placeholder="请输入用户名或者邮箱"></div>
                <div class="clear"></div>
            </div>
            <div class="form-item">
                <div class="item-tit">登录密码：</div>
                <div class="item-input"><input type="password" name="password" placeholder="请输入密码 "
                                               checkData="{rq:true,msg:'请输入正确的密码'}"></div>
                <div class="clear"></div>
            </div>
            <div id="checkCode-area">
                <#if checkCode??>
                    <div class="form-item">
                        <div class="item-tit">验证码：</div>
                        <div class="item-input" style="width:130px;display:inline-block;float:left;margin-left:20px;">
                            <input type="text" name="checkCode" class="check-code" placeholder="请输入验证码"
                                   checkData="{rq:true}"></div>
                        <div class="check_code" style="float:left;display:inline-block;"><a href="javascript:void(0)"
                                                                                            id="refreshCheckCode"><img
                                src="${ulewo.absolutePath}/checkCode"></a></div>
                        <div class="clear"></div>
                    </div>
                </#if>
            </div>
            <div class="form-item">
                <div class="item-tit"></div>
                <div class="item-input"><label><input type="checkbox" class="remember-me not-input" name="rememberMe"
                                                      value="1">记住我的登录信息</label></div>
                <div class="clear"></div>
            </div>
            <div class="form-item">
                <div class="item-tit"></div>
                <div class="item-input"><a href="javascript:void(0)" class="btn login-btn btn-big">登录</a></div>
                <div class="clear"></div>
            </div>
        </form>
    </div>
</div>
<div class="footer">
    <ul>
        <li><a href="${absolutePath}/mobile/sign_in">签到</a></li>
        <li><a href="${absolutePath}/mobile/mobile_spitslot_post.action"></a></li>
        <li><a href="${absolutePath}/mobile/mobile_spitslot">吐槽</a></li>
    </ul>
</div>
</body>
<script>
    $(function () {
        var url = ulewo.curUrl;
        if (url.indexOf("redirect") != -1) {
            ulewo.redirect = url.substring(url.indexOf("redirect") + 9, url.length);
        }
        ulewo.url = {
            login: ulewo.absolutePath + "/login.do"
        };
        $(".login-btn").click(function () {
            login();
        });

        $(document).on("click", "#refreshCheckCode", function () {
            $(this).find("img").attr("src", ulewo.absolutePath + "/checkCode?" + new Date());
        });

        $(document).keyup(function (event) {
            var code = event.keyCode;
            if (code == 13) {
                login();
            }
        });
    });

    function login() {
        var formObj = $("form.u-form").eq(0);
        var result = ulewo.checkForm(formObj);
        if (result) {
            ulewo.ajaxRequest({
                async: true, url: ulewo.url.login, data: formObj.eq(0).serialize(), fun: function (response) {
                    if (response.responseCode.code == ulewo.resultCode.SUCCESS) {
                        ulewo.tipMsg({
                            type: "success", content: "登陆成功，正在跳转....."
                        });
                        if (null == ulewo.redirect || ulewo.redirect == "") {
                            ulewo.redirect = ulewo.absolutePath + "/mobile/sign_in";
                        }
                        document.location.href = ulewo.redirect;
                    } else if (response.responseCode.code == ulewo.resultCode.MOREMAXLOGINCOUNT) {
                        ulewo.tipMsg({
                            type: "error", content: response.errorMsg, timeout: 3000
                        });
                        if ($("#checkCode-area").children().length == 0) {
                            var formItem = $('<div class="form-item"></div>').appendTo($("#checkCode-area"));
                            $('<div class="item-tit">验证码：</div>').appendTo(formItem);
                            $('<div class="item-input" style="width:130px;display:inline-block;float:left;margin-left:20px;"><input type="text" name="checkCode" class="check-code" placeholder="请输入验证码"  checkData="{rq:true}"></div>').appendTo(formItem);
                            $('<div class="check_code" style="float:left;display:inline-block;"><a href="javascript:void(0)" id="refreshCheckCode"><img src="' + ulewo.absolutePath + '/checkCode"></a></div>').appendTo(formItem);
                            $('<div class="clear"></div>').appendTo(formItem);
                        }
                    }
                }
            })
        }
    }
</script>
</html>
